﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SingletonPattern
{
    /// <summary>
    /// 懒汉式，线程安全
    /// </summary>
    public class Singleton2
    {
        private static Singleton2 instance;
        private static readonly object lockHelper = new object();

        private Singleton2() { }

        public static Singleton2 GetInstance()
        {
            lock (lockHelper)
            {
                if (instance == null)
                {
                    instance = new Singleton2();
                }
            }

            return instance;
        }
    }
}
